//
//  LXREmoticonCell.swift
//  表情键盘
//
//  Created by MACBOOK on 16/10/17.
//  Copyright © 2016年 刘袭锐. All rights reserved.
//

import UIKit

class LXREmoticonCell: UICollectionViewCell {
    //FIXME: 定义属性
    var emoticon : Emoticon?{
        didSet{
            // 校验
            guard let emoticon = emoticon else {
                return
            }
            // 1.按钮设置图片
            emoticonBtn.setImage(UIImage(contentsOfFile: emoticon.pngPath ?? ""), for: .normal)
            emoticonBtn.setTitle(emoticon.emojiCode, for: .normal)
            // 2.设置删除按钮
            if emoticon.isRemove {
                emoticonBtn.setImage(UIImage(named: "compose_emotion_delete"), for: .normal)
            }
            
        }
    }
    //FIXME: 懒加载
    fileprivate lazy var emoticonBtn : UIButton = UIButton()
    //FIXME: 重写构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK:- 设置UI界面
extension LXREmoticonCell{
    //FIXME: 设置UI
    fileprivate func setupUI(){
        //1.添加子控件
        contentView.addSubview(emoticonBtn)
        //2.设置按钮的Frame
        emoticonBtn.frame = contentView.bounds
        //3.设置属性
        emoticonBtn.isUserInteractionEnabled = false
        emoticonBtn.titleLabel?.font = UIFont.systemFont(ofSize: 32)
    }
}
